<template>
  <div>
    <div class="search-con search-con-top">
      <div>
        订单编号：
        <Input v-model="searchData.order_sn" style="width: 200px" clearable></Input>
        订单名称：
        <Input v-model="searchData.order_name" style="width: 200px" clearable></Input>
        用户编号：
        <Input v-model="searchData.mobile" style="width: 200px" clearable></Input>
        设计师名称：
        <Input v-model="searchData.design_name" style="width: 200px" clearable></Input>
        订单状态：
        <Select v-model="searchData.order_status" style="width: 150px" filterable clearable>
          <Option v-for="(item, index) in orderStatusList" :value="index" :key="index">{{ item }}</Option>
        </Select>
        订单类型：
        <Select v-model="searchData.order_type" style="width: 150px" filterable clearable>
          <!-- <Option value="1">退款订单</Option> -->
          <Option value="2">投诉订单</Option>
          <Option value="3">加急订单</Option>
        </Select>
      </div>

      <div style="margin-top: 10px">
        下单时间：
        <Date-picker type="date" style="width: 130px" v-model="searchData.create_time_start" clearable></Date-picker> -
        <Date-picker type="date" style="width: 130px" v-model="searchData.create_time_end" clearable></Date-picker>
        定稿时间：
        <Date-picker type="date" style="width: 130px" v-model="searchData.finalize_time_start" clearable></Date-picker> -
        <Date-picker type="date" style="width: 130px" v-model="searchData.finalize_time_end" clearable></Date-picker>
        退款时间：
        <Date-picker type="date" style="width: 130px" v-model="searchData.refund_time_start" clearable></Date-picker> -
        <Date-picker type="date" style="width: 130px" v-model="searchData.refund_time_end" clearable></Date-picker>
        <Button @click="search" type="primary" icon="ios-search" style="margin-left: 10px">搜索</Button>
        <Button @click="reset()" style="margin-left: 10px;">重置</Button>
        <Button type="warning" style="margin-left: 10px" @click="createOrder(0)">添加订单</Button>
      </div>
    </div>
    <br />
    <Table :columns="columns" :data="list" @on-sort-change="customSort" :highlight-row="true" max-height="800" stripe
      border size="small">
      <template slot-scope="{ row, index }" slot="memberSlot">
        <div>
          <Button type="primary" size="small" @click="createOrder(row.id)">编辑</Button>
          <Button type="warning" size="small" @click="shopDetail(row.id)" style="margin-left: 5px;">详情</Button>
          <Button type="error" size="small" @click="delOrder(row.id)" style="margin-left: 5px;">删除</Button>
        </div>
        <div style="margin-top: 5px;">
          <Button type="primary" size="small"
            v-if="row.order_status != 2 && row.order_status != 5 && row.order_status != 6"
            @click="allotOrder(row.id)">分配</Button>
          <Button type="info" size="small" style="margin-left: 5px;"
            v-if="row.order_status != 2 && row.order_status != 5 && row.order_status != 6"
            @click="changeStatus(row.id, row.order_status)">状态</Button>
          <Button type="info" size="small" @click="chatInfo(row.user_id, row.id)" style="margin-left: 5px;">聊天</Button>
        </div>
      </template>
    </Table>
    <Paginate :total="total" @on-change="changePage" @on-page-size-change="changeSize" :current="searchData.page">
    </Paginate>

    <!-- 订单详情 -->
    <Drawer title="详情" :closable="false" width="60" v-model="showDrawer">
      <List header="" footer="" size="small">
        <ListItem>订单编号：{{ orderInfo.order_sn }}</ListItem>
        <ListItem>支付金额：{{ orderInfo.order_amount }}</ListItem>
        <ListItem>待收款：{{ orderInfo.due_in_amount }}</ListItem>
        <ListItem>设计需求：{{ orderInfo.design_need }}</ListItem>
        <ListItem>
          需求文档：<span v-for="item in orderInfo.design_need_file_arr" style="margin-left: 10px;">
            <a :href="item.src">下载文件</a>
          </span>
        </ListItem>
        <ListItem>补充需求：{{ orderInfo.replenish_need }}</ListItem>
        <ListItem>
          补充文档：<span v-for="item in orderInfo.replenish_need_file_arr" style="margin-left: 10px;">
            <a :href="item.src">下载文件</a>
          </span>
        </ListItem>

        <ListItem>销售：{{ orderInfo.sale_name }}</ListItem>
        <ListItem>开票对应公司：{{ orderInfo.invoice_company }}</ListItem>
        <ListItem>开票金额：{{ orderInfo.invoice_amount }}</ListItem>
        <ListItem>开票公司信息：{{ orderInfo.invoice_company_info }}</ListItem>
        <ListItem>开票人姓名：{{ orderInfo.invoice_name }}</ListItem>
        <ListItem>税号：{{ orderInfo.invoice_no }}</ListItem>
        <ListItem>注册地址：{{ orderInfo.invoice_address }}</ListItem>
        <ListItem>联系电话:{{ orderInfo.invoice_tel }}</ListItem>
        <ListItem>开户行：{{ orderInfo.invoice_bank }}</ListItem>
        <ListItem>开户行行号：{{ orderInfo.invoice_bank_code }}</ListItem>
        <ListItem>银行账号：{{ orderInfo.invoice_bank_card }}</ListItem>
        <ListItem>待收款返还金额：{{
          orderInfo.due_in_refund == 1 ? orderInfo.refund_amount : 0
        }}</ListItem>
        <ListItem>备注：{{ orderInfo.remark }}</ListItem>
        <ListItem>尾款：{{ orderInfo.residue_amount }}</ListItem>
        <ListItem>是否加急：{{ orderInfo.is_urgent == 0 ? "否" : "是" }}</ListItem>
        <ListItem v-if="orderInfo.return_path">待收款返还方式：{{
          orderInfo.return_path == 1
          ? "银行卡"
          : orderInfo.return_path == 2
            ? "收款码"
            : "原路返回"
        }}</ListItem>
        <ListItem v-if="orderInfo.return_path == 1">银行卡号:{{ orderInfo.return_bank_card }}</ListItem>
        <ListItem v-if="orderInfo.return_path == 1">银行卡账户名:{{ orderInfo.return_bank_card_name }}</ListItem>
        <ListItem v-if="orderInfo.return_path == 2"><img :src="orderInfo.return_bay_code" style="width: 400px" />
        </ListItem>
      </List>
    </Drawer>

    <!-- 添加订单 -->
    <Modal title="订单信息" width="35" v-model="showAddOrderModal" @on-ok="submitOrder">
      <Form ref="formValidate" :model="orderItem" :label-width="90">
        <FormItem label="客户编号">
          <Input v-model="orderItem.mobile"></Input>
        </FormItem>
        <FormItem label="订单名称">
          <Input v-model="orderItem.order_name"></Input>
        </FormItem>
        <FormItem label="订单金额">
          <Input v-model="orderItem.order_amount" type="number"></Input>
        </FormItem>
        <!-- <FormItem label="订单状态">
                    <Select v-model="orderItem.order_status">
                        <Option v-for="(item, index) in orderStatusList" :value="index" :key="index">{{ item }}</Option>
                    </Select>
                </FormItem> -->
        <FormItem label="代收款">
          <Input v-model="orderItem.due_in_amount" type="number"></Input>
        </FormItem>
        <FormItem label="设计需求">
          <Input v-model="orderItem.design_need" type="textarea"></Input>
        </FormItem>
        <FormItem label="需求文件">
          <Upload ref="upload1" name="file" :show-upload-list="true" :default-file-list="defaultFileList"
            :on-success="handleSuccess" multiple :on-format-error="handleFormatError" :action="action_url"
            :on-remove="handleRemove" style="display: inline-block" :headers="headers">
            <Button icon="ios-cloud-upload-outline">上传文件</Button>
          </Upload>
          <!-- <div v-if="file !== null">文件名称: {{ file.name }} </div> -->
        </FormItem>
        <FormItem label="补充需求">
          <Input v-model="orderItem.replenish_need" type="textarea"></Input>
        </FormItem>
        <FormItem label="补充文件">
          <Upload ref="upload1" name="file" :show-upload-list="true" :default-file-list="defaultFileList1"
            :on-success="handleSuccess1" multiple :on-format-error="handleFormatError" :action="action_url"
            :on-remove="handleRemove1" style="display: inline-block" :headers="headers">
            <Button icon="ios-cloud-upload-outline">上传文件</Button>
          </Upload>
        </FormItem>
        <FormItem label="设计类型">
          <Select v-model="orderItem.design_type" filterable>
            <Option v-for="item in designArr" :value="item.id" :key="item.id">{{
              item.name
            }}</Option>
          </Select>
        </FormItem>
        <FormItem label="业务类型">
          <Select v-model="orderItem.business_type" filterable>
            <Option v-for="item in businessArr" :value="item.id" :key="item.id">{{ item.name }}</Option>
          </Select>
        </FormItem>
        <FormItem label="设计项目">
          <Select v-model="orderItem.program_id" filterable>
            <Option v-for="item in programArr" :value="item.id" :key="item.id">{{ item.name }}</Option>
          </Select>
        </FormItem>
        <FormItem label="支付类型">
          <Select v-model="orderItem.pay_type" filterable>
            <Option v-for="item in payTypeArr" :value="item.id" :key="item.id">{{ item.name }}</Option>
          </Select>
        </FormItem>
        <!-- <FormItem label="设计师">
                    <Select v-model="orderItem.design_id" filterable>
                        <Option v-for="item in designUserArr" :value="item.user_id" :key="item.user_id">{{ item.realname }}
                        </Option>
                    </Select>
                </FormItem>
                <FormItem label="销售">
                    <Select v-model="orderItem.sale_id" filterable>
                        <Option v-for="item in saleUserArr" :value="item.user_id" :key="item.user_id">{{ item.realname }}
                        </Option>
                    </Select>
                </FormItem> -->
        <FormItem label="交稿时间">
          <DatePicker v-model="orderItem.delivery_time" type="date"></DatePicker>
        </FormItem>
        <FormItem label="开票信息">
          <RadioGroup v-model="orderItem.is_invoice">
            <Radio label="0" border>无</Radio>
            <Radio label="1" border>有</Radio>
          </RadioGroup>
        </FormItem>
        <div v-if="orderItem.is_invoice == 1">
          <FormItem label="开票公司">
            <Input v-model="orderItem.invoice_company"></Input>
          </FormItem>
          <FormItem label="开票金额">
            <Input v-model="orderItem.invoice_amount"></Input>
          </FormItem>
          <FormItem label="开票公司信息">
            <Input v-model="orderItem.invoice_company_info"></Input>
          </FormItem>
          <FormItem label="开票人姓名">
            <Input v-model="orderItem.invoice_name"></Input>
          </FormItem>
          <FormItem label="税号">
            <Input v-model="orderItem.invoice_no"></Input>
          </FormItem>
          <FormItem label="注册地址">
            <Input v-model="orderItem.invoice_address"></Input>
          </FormItem>
          <FormItem label="联系电话">
            <Input v-model="orderItem.invoice_tel"></Input>
          </FormItem>
          <FormItem label="开户行">
            <Input v-model="orderItem.invoice_bank"></Input>
          </FormItem>
          <FormItem label="开户行行号">
            <Input v-model="orderItem.invoice_bank_code"></Input>
          </FormItem>
          <FormItem label="银行账号">
            <Input v-model="orderItem.invoice_bank_card"></Input>
          </FormItem>
        </div>
        <FormItem label="代收款返还">
          <RadioGroup v-model="orderItem.due_in_refund">
            <Radio label="0" border>否</Radio>
            <Radio label="1" border>是</Radio>
          </RadioGroup>
        </FormItem>
        <FormItem label="返还金额" v-if="orderItem.due_in_refund == '1'">
          <Input v-model="orderItem.refund_amount"></Input>
        </FormItem>
        <FormItem label="备注">
          <Input v-model="orderItem.remark" type="textarea"></Input>
        </FormItem>
        <FormItem label="备注文件">
          <Upload ref="upload1" name="file" :show-upload-list="true" :default-file-list="defaultFileList2"
            :on-success="handleSuccess2" multiple :on-format-error="handleFormatError" :action="action_url"
            :on-remove="handleRemove2" style="display: inline-block" :headers="headers">
            <Button icon="ios-cloud-upload-outline">上传文件</Button>
          </Upload>
          <!-- <div v-if="file1 !== null">文件名称: {{ file1.name }} </div> -->
        </FormItem>
        <FormItem label="尾款">
          <Input v-model="orderItem.residue_amount"></Input>
        </FormItem>
        <FormItem label="是否加急">
          <RadioGroup v-model="orderItem.is_urgent">
            <Radio label="0" border>否</Radio>
            <Radio label="1" border>是</Radio>
          </RadioGroup>
        </FormItem>
        <FormItem label="是否禁退">
          <RadioGroup v-model="orderItem.forbid_refund">
            <Radio label="0" border>否</Radio>
            <Radio label="1" border>是</Radio>
          </RadioGroup>
        </FormItem>
        <div v-for="item in orderFieldArr" :key="item.id">
          <FormItem :label="item.name">
            <Input v-model="orderItem[item.field]"></Input>
          </FormItem>
        </div>
      </Form>
    </Modal>

    <!-- 订单状态 -->
    <Modal title="设置订单状态" width="35" v-model="showStatusModal" @on-ok="submitOrderStatus">
      <Form ref="formValidate" :model="orderStatusItem" :label-width="90">
        <FormItem label="订单状态">
          <Select v-model="orderStatusItem.order_status">
            <Option v-for="(item, index) in orderStatusList" :value="index" :key="index">{{ item }}</Option>
          </Select>
        </FormItem>
      </Form>
    </Modal>

    <!-- 订单指派 -->
    <Modal title="订单指派" width="35" v-model="showAssignOrderModal" @on-ok="assignOrder">
      <Form ref="formValidate" :model="assignOrderItem" :label-width="90">
        <FormItem label="设计师" v-if="roleId == 3 || roleId == 1">
          <Select v-model="assignOrderItem.design_id" filterable>
            <Option v-for="item in designUserArr" :value="item.user_id" :key="item.user_id">{{ item.realname }}
            </Option>
          </Select>
        </FormItem>
        <FormItem label="销售" v-if="roleId == 2 || roleId == 1">
          <Select v-model="assignOrderItem.sale_id" filterable>
            <Option v-for="item in saleUserArr" :value="item.user_id" :key="item.user_id">{{ item.realname }}
            </Option>
          </Select>
        </FormItem>
      </Form>
    </Modal>

    <!--聊天记录-->
    <Modal title="聊天记录" width="50" v-model="showChatInfo">
      <Table :columns="chatInfoColumns" :data="chatInfoList" size="small" :highlight-row="true" max-height="800" border
        stripe>
        <template slot-scope="{ row, index }" slot="fromSlot">
          <span>{{ row.from_user_name }}：</span>
        </template>
        <template slot-scope="{ row, index }" slot="contentSlot">
          <div>
            <span v-if="row.type == 'webrtc'">语音通话：{{ row.content }}</span>
            <span v-html="row.content" v-if="row.type == 'text' || row.type == 'new_order'"></span>
            <img :src="row.full_src" v-if="row.file_cate == 2 && row.file_id > 0" style="width: 300px;"
              @click="showImg(row.full_src)" />
            <video v-if="row.file_cate == 4 && row.file_id > 0" width="320" height="240" controls>
              <source :src="row.full_src">
            </video>
            <audio controls v-if="row.file_cate == 3 && row.file_id > 0">
              <source :src="row.full_src" type="audio/ogg">
            </audio>
            <a :href="baseImgUrl + row.full_src" v-if="row.file_id && row.file_cate == 1">下载查看</a>
          </div>
        </template>
      </Table>
      <Paginate :total="chatInfoTotal" @on-change="changePage1" @on-page-size-change="changeSize1"
        :current="chatInfoSearchData.page">
      </Paginate>
    </Modal>

    <!-- 图片显示-->
    <Modal v-model="imgShow" :closable="false" width="55">
      <img :src="imgShowUrl" style="width: 1000px;">
    </Modal>
  </div>
</template>

<script>
import config from "@/config";
import { getToken } from "../../libs/util";
import Paginate from "@/components/paginate/paginate.vue";
const baseUrl =
  process.env.NODE_ENV === "development"
    ? config.baseUrl.dev
    : config.baseUrl.pro;
const baseImgeUrl =
  process.env.NODE_ENV === "development"
    ? config.baseImgUrl.dev
    : config.baseImgUrl.pro;
export default {
  name: "orderList",
  components: {
    Paginate,
  },
  data() {
    return {
      roleId: 0,
      baseUrl: baseUrl,
      action_url: baseUrl + "/admin/image/uploadImg",
      headers: {
        Authorization: getToken(),
      },
      baseImgeUrl: baseImgeUrl,
      // 列表
      columns: [
        {
          title: "订单编号",
          align: "center",
          key: "order_sn",
        },
        {
          title: "用户编号",
          align: "center",
          key: "mobile",
          maxWidth: 120,
          tooltip: true,
        },
        {
          title: "订单名称",
          align: "center",
          key: "order_name",
        },
        {
          title: '订单金额',
          align: "center",
          key: 'order_amount',
          maxWidth: 100,
          tooltip: true,
        },
        // {
        //     title: '待收款',
        //     align: "center",
        //     key: 'due_in_amount',
        // },
        // {
        //   title: "设计类型",
        //   align: "center",
        //   key: "design_type_name",
        // },
        // {
        //   title: "业务类型",
        //   align: "center",
        //   key: "business_type_name",
        // },
        {
          title: "设计师",
          align: "center",
          key: "design_name",
          maxWidth: 100,
          tooltip: true,
        },
        {
          title: "销售",
          align: "center",
          key: "sale_name",
          maxWidth: 100,
          tooltip: true,
        },
        // {
        //   title: "设计项目",
        //   align: "center",
        //   key: "program_name",
        // },
        {
          title: "交稿时间",
          align: "center",
          key: "delivery_time",
          maxWidth: 150,
          tooltip: true,
        },
        {
          title: "定稿时间",
          align: "center",
          key: "finalize_time",
          maxWidth: 150,
          tooltip: true,
        },
        {
          title: "退款时间",
          align: "center",
          key: "refund_time",
          maxWidth: 150,
          tooltip: true,
        },
        {
          title: "订单状态",
          align: "center",
          key: "order_status_txt",
          maxWidth: 100,
          tooltip: true,
        },

        {
          title: "创建时间",
          align: "center",
          key: "create_time",
          maxWidth: 150,
          tooltip: true,
        },
        {
          title: "操作",
          align: "center",
          key: "make",
          slot: "memberSlot",
          maxWidth: 180
        },
      ],
      // 数据
      list: [],
      total: 0,
      searchData: {
        page: 1,
        limit: 10,
      },
      defaultFileList: [],
      defaultFileList1: [],
      defaultFileList2: [],
      showDrawer: false,
      orderInfo: {},
      orderItem: {
        is_invoice: "0",
        due_in_refund: "0",
        forbid_refund: "0",
      },
      // 添加订单
      showAddOrderModal: false,
      businessArr: [],
      designArr: [],
      fieldArr: [],
      programArr: [],
      designUserArr: [],
      saleUserArr: [],
      orderFieldArr: [],
      orderStatusList: [],
      payTypeArr: [],
      // 订单状态
      showStatusModal: false,
      orderStatusItem: {
        id: 0,
        order_status: "0",
      },
      // 订单指派
      showAssignOrderModal: false,
      assignOrderItem: {
        id: 0,
      },
      // 聊天记录
      showChatInfo: false,
      chatList: [],
      orderId: 0,
      // 图片显示
      imgShow: false,
      imgShowUrl: '',
      // 聊天记录
      chatInfoList: [],
      chatInfoTotal: 0,
      chatInfoColumns: [
        {
          title: "发送者",
          align: "center",
          key: "from_user_name",
          slot: "fromSlot",
          maxWidth: 200,
        },
        {
          title: "发送内容",
          align: "center",
          key: "content",
          slot: "contentSlot",
        },
        {
          title: "发送时间",
          align: "center",
          key: "create_time",
          maxWidth: 160,
        },
      ],
      chatInfoSearchData: {
        chat_identify: "",
        search: "",
      },
    };
  },
  methods: {
    getList() {
      this.$axios("/admin/order/getList", this.searchData).then((res) => {
        this.list = res.data;
        this.total = res.total;
      });
    },
    search() {
      this.searchData.page = 1;
      this.getList();
    },
    reset() {
      this.searchData = {
        page: 1,
        limit: 10,
      };
      this.getList();
    },
    changePage(page) {
      this.searchData.page = page;
      this.getList();
    },
    changeSize(size) {
      this.searchData.limit = size;
      this.getList();
    },
    customSort(column, key, order) {
      this.searchData.order_by = column.key;
      this.searchData.sort = column.order;
      this.getList();
    },
    shopDetail(id) {
      this.$axios("/admin/order/getOrderInfo", { id: id }).then((res) => {
        this.orderInfo = res;
      });
      this.showDrawer = true;
    },
    exportOrderExcel() {
      this.$axios("/admin/order/exportOrderExcel", this.searchData).then(
        (res) => {
          this.$refs.load.href = baseImgeUrl + res.file_path;
          this.$refs.load.click();
        }
      );
    },
    importOrderExcel(response) {
      this.$axios("/admin/order/batchSendGoods", {
        file_path: response.data.src,
      }).then(() => {
        this.$Message.success("执行成功");
      });
    },
    getOrderStatusArr() {
      this.$axios("/admin/order/getOrderStatusArr").then((res) => {
        this.orderStatusList = res;
      });
    },
    createOrder(id) {
      // this.getBusinessArr();
      // this.getDesignArr();
      // this.getOrderFieldArr();
      // this.getPayTypeArr();
      // this.getProgramArr();
      // this.getDesignUserArr();
      // this.getSaleUserArr();
      this.getCreateOrderOptionArr();
      if (id > 0) {
        let time = 0;
        this.$axios("/admin/order/getOrderInfo", {
          id: id,
        }).then((res) => {
          let timestamp = Math.floor(Date.now() / 1000);
          let updateTime = res.create_time;
          if (timestamp - updateTime < 3600) {
            time = Math.floor((timestamp - updateTime) / 60);
            this.$Modal.confirm({
              title: "确定",
              content: "<p>订单在" + time + "分钟前更新，您确定要更新吗？</p>",
              onOk: () => {
                this.orderItem = res;
                this.orderItem.is_invoice = this.orderItem.is_invoice + "";
                this.orderItem.due_in_refund =
                  this.orderItem.due_in_refund + "";
                this.orderItem.is_urgent = this.orderItem.is_urgent + "";
                this.defaultFileList = this.orderItem.design_need_file_arr;
                this.defaultFileList1 = this.orderItem.replenish_need_file_arr;
                this.defaultFileList2 = this.orderItem.remark_file_id_arr;
                this.showAddOrderModal = true;
              },
              onCancel: () => {
                this.$Message.info("取消操作");
              },
            });
          } else {
            this.orderItem = res;
            this.orderItem.is_invoice = this.orderItem.is_invoice + "";
            this.orderItem.due_in_refund = this.orderItem.due_in_refund + "";
            this.orderItem.is_urgent = this.orderItem.is_urgent + "";
            this.defaultFileList = this.orderItem.design_need_file_arr;
            this.defaultFileList1 = this.orderItem.replenish_need_file_arr;
            this.defaultFileList2 = this.orderItem.remark_file_id_arr;
            this.showAddOrderModal = true;
          }
        });
      } else {
        this.orderItem = {
          is_invoice: "0",
          due_in_refund: "0",
          is_urgent: "0",
          forbid_refund: "0",
          design_need_file: [],
          replenish_need_file: [],
        };
        this.defaultFileList = [];
        this.defaultFileList1 = [];
        this.defaultFileList2 = [];
        this.showAddOrderModal = true;
      }
    },
    getCreateOrderOptionArr() {
      this.$axios("/admin/order/getCreateOrderOptionArr").then((res) => {
        this.businessArr = res.businessArr;
        this.designArr = res.designArr;
        this.programArr = res.programArr;
        this.payTypeArr = res.payArr;
        this.designUserArr = res.designerArr;
        this.saleUserArr = res.saleArr;
        this.orderFieldArr = res.fieldArr;
      });
    },
    getBusinessArr() {
      this.$axios("/admin/business/getArr").then((res) => {
        this.businessArr = res;
      });
    },
    getDesignArr() {
      this.$axios("/admin/design/getArr").then((res) => {
        this.designArr = res;
      });
    },
    getProgramArr() {
      this.$axios("/admin/program/getArr").then((res) => {
        this.programArr = res;
      });
    },
    getPayTypeArr() {
      this.$axios("/admin/pay/getArr").then((res) => {
        this.payTypeArr = res;
      });
    },
    getDesignUserArr() {
      this.$axios("/admin/user/getDesignUserArr").then((res) => {
        this.designUserArr = res;
      });
    },
    getSaleUserArr() {
      this.$axios("/admin/user/getSaleUserArr").then((res) => {
        this.saleUserArr = res;
      });
    },
    getOrderFieldArr() {
      this.$axios("/admin/order/getOrderFieldArr").then((res) => {
        this.orderFieldArr = res;
      });
    },
    submitOrder() {
      this.$axios("/admin/order/save", this.orderItem).then((res) => {
        this.$Message.success("添加成功");
        this.showAddOrderModal = false;
        this.getList();
      });
    },
    handleSuccess(res, file, fileList) {
      let arr = [];
      fileList.forEach(function (params) {
        arr.push(params.response.data.file_id);
      });
      this.orderItem.design_need_file = arr;
    },
    handleSuccess1(res, file, fileList) {
      let arr = [];
      fileList.forEach(function (params) {
        arr.push(params.response.data.file_id);
      });
      this.orderItem.replenish_need_file = arr;
    },
    handleRemove(file, fileList) {
      let arr = [];
      fileList.forEach(function (params) {
        arr.push(params.response.data.file_id);
      });
      this.orderItem.design_need_file = arr;
    },
    handleRemove1(file, fileList) {
      let arr = [];
      fileList.forEach(function (params) {
        arr.push(params.response.data.file_id);
      });
      this.orderItem.replenish_need_file = arr;
    },
    handleSuccess2(res, file, fileList) {
      let arr = [];
      fileList.forEach(function (params) {
        arr.push(params.response.data.file_id);
      });
      this.orderItem.remark_file_id = arr;
    },
    handleRemove2(file, fileList) {
      let arr = [];
      fileList.forEach(function (params) {
        arr.push(params.response.data.file_id);
      });
      this.orderItem.remark_file_id = arr;
    },
    handleFormatError(file) {
      this.$Notice.warning({
        title: "文件格式错误",
        desc: "不支持该文件类型",
      });
    },
    changeStatus(id, status) {
      this.orderStatusItem.id = id;
      this.orderStatusItem.order_status = status;
      this.showStatusModal = true;
    },
    submitOrderStatus() {
      this.$axios("/admin/order/changeOrderStatus", this.orderStatusItem).then(
        (res) => {
          this.$Message.success("执行成功");
          this.showAddOrderModal = false;
          this.getList();
        }
      );
    },
    allotOrder(id) {
      this.assignOrderItem.id = id;
      this.getDesignUserArr();
      this.getSaleUserArr();
      this.showAssignOrderModal = true;
    },
    assignOrder() {
      this.$axios("/admin/order/assign", this.assignOrderItem).then((res) => {
        this.$Message.success("执行成功");
        this.showAssignOrderModal = false;
        this.getList();
      });
    },
    delOrder(id) {
      this.$Modal.confirm({
        title: "删除",
        content: "<p>您确定要删除订单吗？</p>",
        onOk: () => {
          this.$axios("/admin/order/del", { id: id }).then((res) => {
            this.$Message.success("删除成功");
            this.getList();
          });
        },
        onCancel: () => {
          this.$Message.info("取消操作");
        },
      });
    },
    chatInfo(user_id, order_id) {
      this.chatInfoSearchData.chat_identify = user_id + '-0-' + order_id;
      this.showChatInfo = true;
      this.getChatInfo();
    },
    getChatInfo() {
      this.$axios("/admin/chat/getChatRecord", this.chatInfoSearchData).then((res) => {
        this.chatInfoList = res.data
        this.chatInfoTotal = res.total
      });
    },
    showImg(url) {
      this.imgShow = true;
      this.imgShowUrl = url;
    },
    changePage1(page) {
      this.chatInfoSearchData.page = page;
      this.getChatInfo();
    },
    changeSize1(size) {
      this.chatInfoSearchData.limit = size;
      this.getChatInfo();
    },
  },
  activated() {
    let type = this.$route.query.ik;
    if (type > 0) {
      // 待分配
      if (type == 1) {
        this.searchData.order_status = 0;
      }
      // 进行中
      if (type == 2) {
        this.searchData.order_status = 1;
      }
      // 定稿
      if (type == 3) {
        this.searchData.order_status = 2;
      }
      // 投诉
      if (type == 4) {
        this.searchData.complaint_content = 1;
      }
      // 暂停
      if (type == 5) {
        this.searchData.order_status = 4;
      }
      // 死单
      if (type == 6) {
        this.searchData.order_status = 3;
      }
      // 投诉已处理
      if (type == 7) {
        this.searchData.is_complaint = 2;
      }
      // 投诉未处理
      if (type == 8) {
        this.searchData.is_complaint = 1;
      }
      // 待退款
      if (type == 9) {
        this.searchData.order_status = 5;
      }
      // 已退款
      if (type == 10) {
        this.searchData.order_status = 6;
      }
      // 待收款未返还
      if (type == 11) {
        this.searchData.due_is_refund = 0;
      }
      // 待收款已返还
      if (type == 12) {
        this.searchData.due_is_refund = 1;
      }
      // 未上传发票
      if (type == 13) {
        this.searchData.is_open = 0;
      }
      // 已上传发票
      if (type == 14) {
        this.searchData.is_open = 1;
      }
    }
    this.roleId = localStorage.getItem("roleId");
    this.getOrderStatusArr();
    this.getList();
  },
  created() {
    // this.roleId = localStorage.getItem("roleId");
    // this.getOrderStatusArr();
    // this.getList();
  },
};
</script>
